Title: SQL W3S (By-BKK) / 037 Select Into
Tags: Obsidian_to_Anki

Q: What does the SQL SELECT INTO statement do?
A: It copies data from one table into a new table

Q: True or False: SELECT INTO creates a new table based on an existing table’s data and structure
A: True

Q: How do you copy all columns from an old table into a new table with SELECT INTO?
A: Use: SELECT * INTO newtable FROM oldtable

Q: How do you copy only selected columns with SELECT INTO?
A: Specify column names: SELECT column1, column2 INTO newtable FROM oldtable

Q: Can you rename columns when using SELECT INTO?
A: Yes, by using the AS clause

Q: What does the IN clause do in SELECT INTO?
A: Copies the new table to a different database

Q: Example: Copy all data into a backup table called CustomersBackup2017
A: SELECT * INTO CustomersBackup2017 FROM Customers

Q: How do you copy data for only 'Germany' customers into a new table with SELECT INTO?
A: Use: SELECT * INTO CustomersGermany FROM Customers WHERE Country = 'Germany'

Q: Can SELECT INTO be used with joins?
A: Yes, you can copy data from more than one table using joins

Q: How do you create an empty table with a schema copied from another table using SELECT INTO?
A: Add a WHERE clause that returns no data: SELECT * INTO newtable FROM oldtable WHERE 1 = 0

Q: SELECT INTO statement syntax - What comes after SELECT and before FROM?
A: INTO newtable

Q: True or False: SELECT INTO modifies data in the existing table
A: False

Q: Example: How to copy just CustomerName and ContactName into a new table
A: SELECT CustomerName, ContactName INTO CustomersBackup2017 FROM Customers

Q: How is new table’s column type and name determined in SELECT INTO?
A: It’s based on the old table's column names and types

Q: SELECT INTO can be used to copy data into an external database. How?
A: By using: SELECT * INTO newtable IN externaldb FROM oldtable

Q: Reverse card: To copy data into a new table, which SQL statement is used?
A: SELECT INTO

Q: True or False: You must specify column types explicitly when creating a table with SELECT INTO
A: False